package com.hzhk.happyrent.ui.adapter.my;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.card.CardHotModel;
import com.hzhk.happyrent.bean.person.AddressModel;
import com.hzhk.happyrent.ui.activity.UpdateAddressActivity;
import com.hzhk.happyrent.ui.adapter.BaseAdapter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by soft_zzc on 2017/11/27.
 */

public class AddressAdapter extends BaseAdapter<AddressModel.DataBean.UserAddressBean> {



    private Context context;
    private Logger log = LoggerFactory.getLogger(this.getClass().getName());
    private CardHotModel cardHotModel;

    public AddressAdapter(Context context) {
        super(context);
        this.context = context;
        log.debug("jump into CardHotAdapter");
    }


    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_address_list, null);
            viewHolder = new ViewHolder(convertView, position, mContext);
            viewHolder.setData(mList.get(position));
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
            viewHolder.setData(mList.get(position));
        }
        return convertView;
    }


    static class ViewHolder {
        private Logger log = LoggerFactory.getLogger(this.getClass().getName());
        private Context context;
        int position;
        private String uil;
        @BindView(R.id.address_list_name)
        TextView addressListName;
        @BindView(R.id.address_item_phone)
        TextView addressItemPhone;
        @BindView(R.id.address_list_address)
        TextView addressListAddress;
        @BindView(R.id.address_item_delete)
        TextView addressItemDelete;
        @BindView(R.id.address_item_edit)
        TextView addressItemEdit;
        @BindView(R.id.address_list_acquiescence)
        TextView addressListAcquiescence;
        @BindView(R.id.image3)
        ImageView image3;
        AddressModel.DataBean.UserAddressBean userAddressBean;

        ViewHolder(View view, int position, Context context) {
            this.position = position;
            this.context = context;
            ButterKnife.bind(this, view);
        }

        public void setData(final AddressModel.DataBean.UserAddressBean userAddressBean) {
            //ShowImageUtils.showImageView(App.getContext(),cardTopPic,cardsBean.getImage());
            this.userAddressBean = userAddressBean;
            if (position != 0) {
                //addressListAcquiescence.setVisibility(View.GONE);
                image3.setImageResource(R.drawable.address8);
            }
            addressListName.setText(userAddressBean.getUser_name());
            addressItemPhone.setText(userAddressBean.getPhone());
            addressListAddress.setText(userAddressBean.getArea() + userAddressBean.getAddress());

        }

        @OnClick({R.id.address_item_delete, R.id.address_item_edit,R.id.address_list_acquiescence,R.id.image3})
        public void onViewClicked(View view) {
            switch (view.getId()) {
                case R.id.address_list_acquiescence:
                case R.id.image3:
                case R.id.address_item_delete:
                case R.id.address_item_edit:
                    Intent intent = new Intent(context, UpdateAddressActivity.class);
                    intent.putExtra("type", userAddressBean.getId());
                    intent.putExtra("name", userAddressBean.getUser_name());
                    intent.putExtra("phone", userAddressBean.getPhone());
                    intent.putExtra("address", userAddressBean.getAddress());
                    intent.putExtra("area", userAddressBean.getArea());
                    intent.putExtra("check_default", userAddressBean.getCheck_default());
                    context.startActivity(intent);
                    break;
            }
        }
    }
}
